$(function(){
	$('#finish_back_cs_no').combobox({    
		url:'admin/system/allCustomerNos.do',    
		valueField:'text',    
		textField:'text',
		required:true,
		panelHeight:'auto'
	});
	$("#finish_back_datagrid").datagrid({    
	    url:'customer/overseas_business/allFinishBackOrder.do',
	    loadMsg:'数据加载中···',
	    fit:'true',
	    idField:'id',
	    pagination:true,
	    rownumbers:true,//行号  
	    checkOnSelect : true,
		selectOnCheck : true,
	    columns:[[
	    {
	    	field : "ck",
	    	checkbox : true
	    }, 
		{
			field : "id",
			hidden : true
		},     
	    {
			field:'customer_no',
			title:'客户编号',
			width:200,
			align:'center'
	    },    
	    {
	    	field:'order_no',
	    	title:'订单编号',
	    	width:200,
	    	align:'center'
	     },
//	     {
//	    	 field:'order_fee',
//	    	 title:'订单费用',
//	    	 width:120,
//	    	 align:'center',
//	    	 formatter:function(value, row, index){
//	    		 var a;
//	    		 var b;
//	    		 if(row['laborFee']==null){
//	    			 a = 0;
//	    		 }
//	    		 if(row['postage']==null){
//	    			 b = 0;
//	    		 }
//	    		 if(row['laborFee']==null && row['postage']==null ){
//	    			 return "待定";
//	    		 }else{
//	    			 return row['laborFee']+row['postage'];
//	    		 }
//	    	 }
//	    },
	     {
	    	 field:'business_type',
	    	 title:'订单业务类型',
	    	 width:200,
	    	 align:'center'
	    },{

	    	field:'state',
	    	title:'订单处理状态',
	    	width:150,
	    	align:'center',
	        formatter: function(value,row,index){
	        	 if(value==0)
	    			 return "待审核";
	    		 else if(value==1)
	    			 return "审核中";
	    		 else if(value==2)
	    			 return "收货中";
	    		 else if(value==3)
	    			 return "入库中";
	    		 else if(value==4)
	    			 return "入库完成";
	    		 else
	    			 return "状态出错";
	        }
	    	},

	    {
   	    	field:'create_tm',
   	    	title:'下单时间',
   	    	width:200,
   	    	align:'center',
   	        formatter: function(value,row,index){
   	        	return getTime(value);
   	        }},
	     {

		    	field:'detail_check',
		    	title:'订单查看',
		    	width:100,
		    	align:'center', 
		    	formatter:function(value, row, index){
		    		return "<a href='javascript:void(0)' onclick=\"showfinishBackDetail('"+row.order_no+"')\">查看详情</a>";
		    	}
		    }
	    ]],
	    fitColumns:true,
	    toolbar:'#finish_back_tb'
	});  	
});
function getTime(old) {
	var date = new Date(old);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	if (month < 10)
		month = "0" + month;
	var day = date.getDate();
	if (day < 10)
		day = "0" + day;
	var hour = date.getHours();
	if (hour < 10)
		hour = "0" + hour;
	var minute = date.getMinutes();
	if (minute < 10)
		minute = "0" + minute;
	var seconds = date.getSeconds();
	if (seconds < 10)
		seconds = "0" + seconds;
	var newDate = year + "-" + month + "-" + day + " " + hour + ":" + minute
			+ ":" + seconds;
	return newDate;
}

function showfinishBackDetail(order_no){
	$("#finish_back_detail_dialog").dialog({    
	    title: '查看订单详情',    
	    width: 650,   
	    height: 550,
	    closed: false,    
	    cache: false,
	    iconCls:'icon-eye',
	    href: 'customer/overseas_business/show_detail?order_no='+order_no,    
	    modal: true,
	    buttons:[{
			text:'关闭',
			handler:function(){
				$("#finish_back_detail_dialog").dialog('close');
				$("#finish_back_datagrid").datagrid('uncheckAll');
			}
		}]      
	});    
}

/**查询条件*/
function queryfinishback(){
	$("#finish_back_datagrid").datagrid({
		queryParams: {
			customerNo: $("input[name='finishBackCustomerNo']").val(),
			orderNo: $("input[name='finishBackOrderNo']").val(),
			tmFrom : $("input[name='finishBackTmFrom']").val(),
			tmTo : $("input[name='finishBackTmTo']").val()
		}
	});
}
function resetfinishback(){
	$("input[name='allBackCustomerNo']").val("");
	$('#finish_back_cs_no').combobox("setValue","");
	$("input[name='finishBackOrderNo']").val("");
	$("input[name='finishBackTmFrom']").val("");
	$("input[name='finishBackTmTo']").val("");
	$("#finishBackTmFrom").datebox("setValue","");
	$("#finishBackTmTo").datebox("setValue","");
	queryfinishback();
}
function delfinishBack(){
	var orderNos = [];
	var rows = $("#finish_back_datagrid").datagrid('getChecked');
	if(rows==null||rows.length==0){
		$.messager.alert('提示信息','请选则要删除的订单!');
	}else {
		$.messager.confirm('确认消息', '确定删除这些订单信息?', function(r){
			if (r){
				for(var i = 0;i<rows.length;i++)
					orderNos.push(rows[i].order_no);
				$.ajax({
					type:'POST',
					dataType:'json',
					url:'admin/order/all/delOrders',
					data:{"orderNos": orderNos }, 
					traditional:true,
					success:function(data){
						$.messager.alert('消息',data.msg);
						if(data.success){
							$("#finish_back_datagrid").datagrid('reload');
							$("#finish_back_datagrid").datagrid('uncheckAll');
							$("#proce_back_datagrid").datagrid('reload');
							$("#wait_back_datagrid").datagrid('reload');
							$("#all_back_datagrid").datagrid('reload');
						}
					}
				});
			}
		});
	}
}
/**
 * 修改订单
 * @returns
 */
function editfinishBack(){
	var rows = $("#finish_back_datagrid").datagrid('getChecked');
	if (rows && rows.length == 1) {
		   $("#finish_back_mod_dialog").dialog({    
		    title: '修改订单信息',    
		    width: 550,   
		    height: 500,
		    closed: false,    
		    cache: false,
		    iconCls:'icon-add',
		    href: 'customer/overseas_business/toBackMod?order_no='+rows[0].order_no,    
		    modal: true,
		    buttons:[{
				text:'提交',
				handler:function(){
					subBackMod();
					$("#finish_back_datagrid").datagrid('uncheckAll');
				}},{
				text:'关闭',
				handler:function(){
					$("#finish_back_mod_dialog").dialog('close');
					$("#finish_back_datagrid").datagrid('uncheckAll');
				}
			}]      
		});    
	} else {
		parent.$.messager.alert('提示', "请选择一条订单！");
	}
	$("#finish_back_datagrid").datagrid('uncheckAll');
}